package com.xiaoq.sites.repository.impl;

import org.apache.commons.lang3.StringUtils;
import org.mongodb.morphia.Datastore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.xiaoq.coms.util.IdGenerator;
import com.xiaoq.sites.entity.MerchantEntity;
import com.xiaoq.sites.repository.IMerchantRepository;
@Repository
public class MerchantRepositoryImpl implements IMerchantRepository {
	
	@Autowired
	private Datastore datastore;

	private static final Logger LOG = LoggerFactory.getLogger(MerchantRepositoryImpl.class);
	@Override
	public boolean save(MerchantEntity merchant) {
			String id = merchant.getId();
			MerchantEntity merchantIDB = datastore.get(MerchantEntity.class,id);
			if(merchantIDB!=null){
				String name = merchant.getName();
				if(StringUtils.isNotEmpty(name)){
					merchantIDB.setName(name);
				}
				String buziNo = merchant.getBuziNo();
				if(StringUtils.isNotEmpty(buziNo)){
					merchantIDB.setBuziNo(buziNo);
				}
				String corpReprz = merchant.getCorpReprz();
				if(StringUtils.isNotEmpty(corpReprz)){
					merchantIDB.setCorpReprz(corpReprz);
				}
				String buziLicNo = merchant.getBuziLicNo();
				if(StringUtils.isNotEmpty(buziLicNo)){
					merchantIDB.setBuziLicNo(buziLicNo);
				}
				String  corpFrontPhoto = merchant.getCorpFrontPhoto();
				if(StringUtils.isNotEmpty(corpFrontPhoto)){
					merchantIDB.setCorpFrontPhoto(corpFrontPhoto);
				}
				String corpReversePhoto = merchant.getCorpReversePhoto();
				if(StringUtils.isNotEmpty(corpReversePhoto)){
					merchantIDB.setCorpReversePhoto(corpReversePhoto);
				}
				// 现在先用字符串处理吧,后期看看要不要使用枚举处理
				merchantIDB.setStatus("10");
			}
			datastore.save(merchant);
			return true;
		
	}
	@Override
	public MerchantEntity findById(String id) {
		
		return datastore.get(MerchantEntity.class, id);
	}

}
